package org.smile.validate.rule;

import org.smile.util.HashCode;
import org.smile.util.Objects;
import org.smile.validate.Rule;

public abstract  class AbstractRule implements Rule {
    @Override
    public int hashCode() {
        int hash= HashCode.hash(HashCode.SEED,this.getFieldName());
        hash=HashCode.hash(hash,this.getType().name());
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Rule){
            Rule other=(Rule)obj;
            if(Objects.notEquals(this.getFieldName(),other.getFieldName())){
                return false;
            }
            if(Objects.notEquals(this.getType(),other.getType())){
                return false;
            }

            if(Objects.notEquals(this.getValue(),other.getValue())){
                return false;
            }

            if(Objects.notEquals(this.getRegexp(),other.getRegexp())){
                return false;
            }

            if(Objects.notEquals(this.getRange(),other.getRange())){
                return false;
            }

            if(Objects.notEquals(this.ifnull(),other.ifnull())){
                return false;
            }
            return true;
        }
        return  false;
    }

    @Override
    public String toString() {
        return this.getFieldName()+":"+this.getType().name();
    }
}
